import axios from 'axios'
import store from '../store/index'
import request2 from '@/utils/request'
function createHttp() {
    const instance = axios.create({ baseURL: 'http://47.113.217.249:8008/admin-api' })
    instance.interceptors.request.use((config) => {
        if (config.params == null) {
            config.params = {}
        }
        config.params['companyCode'] = localStorage.getItem('CompanyCode2')
        config.headers = {...config.headers, ...getHeader() }
        return config
    })
    instance.interceptors.response.use((res) => {
        return res
    })
    return instance
}

function getHeader() {
    if (process.env.VUE_APP_PLANTFORM == "YQ") {
        return {
            timestamp: '1710154302',
            nonce: '5200442419108470309',
            appKey: 'safetyhuadp',
            signature: '9A8755805D72ED3BBA5CD7E5EE64A0633E53EA97D430929EE76283B8532CC8EB',
        }
    } else {
        return {
            timestamp: '1703514207',
            nonce: '5412642519688163665',
            appKey: 'safetyhuadp',
            signature: 'F49B8AC3B6E2B502F278A853B2B2FD2DF31BB7EBB2CCD68D9F38C4308FF2AF44',
        }
    }

}

const request = createHttp()

const version = '/safetyhua/bi/v3'

//获取摄像头列表
export async function getBiCameraList(params) {
    return (await request.get(`${version}/getCameraList`, { params: params })).data.data
    // return (await request.get(`/ai/GetCameraPreviewURL`, { params: params })).data.data

}
export async function getBiCameraList_qy() {
    // return (await request2.get(`/ai/GetDevice`, { params: {businessId:"XgXsvPdbqMTH"} })).data.data
return   (await request2.get(`/ai/GetDevice`, { params: {businessId:"XgXsvPdbqMTH"} })).data.list


}

///获取产品列表
export async function getDbProductList(id) {
    return (
        await request.get('/iot/product/list', {
            params: {
                ids: id
            }
        })
    ).data.data
}

//获取监控点
export async function getBiCameraListV2(params) {
    return (await request.post(`${version}/getCameraList`, params)).data.data
}

//获取视频流播放
export async function getDeviceStreamPlay(params) {
    return (await request.post(`${version}/getCameraPreviewURL`, params)).data.data
}
export async function getDeviceStreamPlay_qy(params) {
    let res=(await request2.get(`/ai/GetCameraPreviewURL`, {params})).data
    return res
}
//获取设备在线状态
export async function getDeviceOnLineState(params) {
    return (await request.post(`${version}/getCameraOnlineList`, params)).data.data
}